<?php
	//----------------------------------------------------------
	// BeSpoke API - User Info Node
	// Author  : Lance Kuo
	// Created : 2012/07/25
	// Version : V1.0.0.0
	// Note    : BeSpoke API function for User Account Info Node request/response XML formate Data
	// History : 2012/07/25 Created by Lance Version 1, UnTest
	//----------------------------------------------------------
	include("mysql_connect.php");

	$xml = simplexml_load_file('php://input');
	//$xml = simplexml_load_file('userInfo.xml');
	//$xml = simplexml_load_string('<Authentication UserName="development@thetigerparty.com" Password="" Name="" Source="" Plaintext="True" />');
	//$array = $xml->attributes();
	
	foreach( $xml->attributes( ) as $attr)
	{
		$AttrArray[] = $attr;
	}
	
	$strSqlCommand = "SELECT MediaDownloadPath FROM Global_Config WHERE 1";
		$result = mysql_query($strSqlCommand);
		$row = @mysql_fetch_array($result);	
	$ServerPath = $row['MediaDownloadPath'];
	
//	echo $strSqlCommand . " 2:" . $result . " 3:" . $row.  " 4:".$ServerPath;
	
	$UserName = $AttrArray[0];
	$Password= $AttrArray[1];
	$Name = $AttrArray[2];
	$Source = $AttrArray[3];
	$Plaintext = $AttrArray[3];
	
    //Link to MySql
    
	if( strlen($UserName) != 0)
	{
    	$strSqlCommand = "SELECT idUSER, Name, Level, Organization, Enable, Default_Channel,
		                    FaceBookID, FaceBookToken, FaceBookSwitch,
							TwitterKey, TwitterSecret, TwitterSwitch,
							TumblrName, TumblrSwitch, InstagramToken, InstagramSwitch
							FROM user
							WHERE Email = '".$UserName."' 
							AND Password = '".$Password."' ";
							
		$result = mysql_query($strSqlCommand);
		$rowUserInfo = @mysql_fetch_array($result);
		if ($rowUserInfo=="")
		{
			
			$strSqlCommand = "SELECT idUSER, Name, Level, Organization, Enable, Default_Channel,
								FaceBookID, FaceBookToken, FaceBookSwitch,
								TwitterKey, TwitterSecret, TwitterSwitch,
								TumblrName, TumblrSwitch, InstagramToken, InstagramSwitch
								FROM user
								WHERE Email = '".$UserName."'";
							
			$result = mysql_query($strSqlCommand);
			$rowUserInfo = @mysql_fetch_array($result);
			
			//Check Source is or not Social.
			if(($Source!="Bespoke")&&($rowUserInfo==""))
			{
				$strSqlCommand = "INSERT INTO user (Name, Email, Password, Default_Channel, Enable, Level, Organization) 
									VALUES ('".$Name."','".$UserName."','','0','0','iPadUser','".$Source."')";
				
				if (!mysql_query($strSqlCommand))
 				{
	 				echo mysql_error();
					return;
 				}
				$strSqlCommand = "SELECT idUSER, Name, Level, Organization, Enable, Default_Channel
			 					FROM user
								WHERE Email = '".$UserName."'";
							
				if (!$result = mysql_query($strSqlCommand))
 				{
	 				echo mysql_error();
					return;
 				}
				$rowUserInfo = @mysql_fetch_array($result);
			}
			else if (($Source=="Bespoke")&&($rowUserInfo==""))
			{
				echo '<Unsuccess Message="The username is incorrect." Domain="UserInfo" />';
				return;
			}
			else if (($Source=="Bespoke")&&($rowUserInfo!=""))
			{
				echo '<Unsuccess Message="The password is incorrect." Domain="UserInfo" />';
				return;
			}
		}
		
		
		$strSqlCommand = "SELECT idCHANNELS, Name
								FROM channels
								WHERE idCHANNELS = '".$rowUserInfo['Default_Channel']."'";
								
		$result = mysql_query($strSqlCommand);
		$rowUserChannel = @mysql_fetch_array($result);
		
		echo '<AccountInfo UserName="'.$UserName.'" Level="'.$rowUserInfo['Level'].'" ';
		echo 'Name="'.$rowUserInfo['Name'].'" Organization="'.$rowUserInfo['Organization'].'" Channel="'.$rowUserChannel['Name'].'" ';
		echo 'Enable="'.$rowUserInfo['Enable'].'">';

		//---------Level 1 Share Group-------------------------------------------------------------------------------//		    	
		$strSqlCommand = "SELECT idGROUP, Name
							FROM sharegroup tbGroup
							WHERE tbGroup.USER_idUSER = ".$rowUserInfo['idUSER'];
							
		$resultGroup = mysql_query($strSqlCommand);
		if( @mysql_num_rows($resultGroup) > 0 )
		{
			echo "<ShareGroup>";
			//---------Level 2 Group(List) in ShareGroup--------------------------------------------------------------//		
			while($rowGroup = @mysql_fetch_array($resultGroup))
			{
				echo '<Group ID="'.$rowGroup['idGROUP'].'" Name="'.$rowGroup['Name'].'">';
				
				//---------Level 3 User(List) in Gruop--------------------------------------------------------------------//	
				$strSqlCommand = "SELECT idUSER, Name, Email
									FROM spot_group_users tbSpot, user tbUser
									WHERE tbSpot.GROUP_idGROUP = ".$rowGroup['idGROUP']." 
									AND tbSpot.USER_idUSER = tbUser.idUSER 
									AND tbUser.idUSER != ".$rowUserInfo['idUSER'];
							
				$resultUser = mysql_query($strSqlCommand);
				while($rowUser = @mysql_fetch_array($resultUser))
				{
					echo '<User ID="'.$rowUser['idUSER'].'" Name="'.$rowUser['Name'].'" Email="'.$rowUser['Email'].'" />';
				}
				// -----------------End of User List in Group---------------------//

				
				echo '</Group>';
			}
			// -----------------End of Group List in ShareGroup---------------------//
			echo "</ShareGroup>";
			
		}
		// -----------------End ShareGroup---------------------//

		//---------Level 1 MyBoard-------------------------------------------------------------------------------//
/*
		$strSqlCommand = "SELECT GROUP_idGROUP, STORYBOARD_idSTORYBOARD, Name
							FROM spot_sb_group tbSpot, storyboard tbBoard
							WHERE tbSpot.USER_idUSER = ".$rowUserInfo['idUSER']." 
							AND tbSpot.STORYBOARD_idSTORYBOARD = tbBoard.idSTORYBOARD 
							GROUP BY STORYBOARD_idSTORYBOARD";
/*/
		$strSqlCommand = "SELECT idSTORYBOARD, Name FROM storyboard WHERE storyboard.USER_idUSER = ".$rowUserInfo['idUSER'];
//*/							
		$resultBoard = mysql_query($strSqlCommand);
		if( @mysql_num_rows($resultBoard) > 0 )
		{
			echo '<MyBoard >';
			//---------Level 2 Board List-------------------------------------------------------------------------------//
			while($rowBoard = @mysql_fetch_array($resultBoard))
			{
				$strBord = '<Board ID="'.$rowBoard['idSTORYBOARD'].'" Name="'.$rowBoard['Name'].'" ShareGroup="';
				/**$strSqlCommand = "Select STORYBOARD_idSTORYBOARD, GROUP_idGROUP
									From spot_user_sb_m, media, spot_group_media_sb
									where spot_user_sb_m.MEDIA_idMEDIA = media.idMEDIA 
									AND media.idMEDIA = spot_group_media_sb.MEDIA_idMEDIA 
									AND media.idMEDIA = spot_group_media_sb.STORYBOARD_idSTORYBOARD 
									and STORYBOARD_idSTORYBOARD = ".$rowBoard['idSTORYBOARD']."
									GROUP BY GROUP_idGROUP";
				**/			
				$strSqlCommand = "SELECT GROUP_idGROUP FROM spot_group_media_sb 
				                  WHERE STORYBOARD_idSTORYBOARD = ".$rowBoard['idSTORYBOARD']." GROUP BY GROUP_idGROUP";
				$resultSGID = mysql_query($strSqlCommand);
				while($rowSGID = @mysql_fetch_array($resultSGID))
				{
					$strBord .= $rowSGID['GROUP_idGROUP'].',';
				}
				if(mysql_num_rows($resultSGID) > 0)
					echo substr($strBord, 0, -1) . '">';
				else
					echo $strBord . '">';

				//---------Level 3 Media List-------------------------------------------------------------------------------//

				$strSqlCommand = "SELECT idMEDIA, MEDIA_TYPE_idMEDIA_TYPE, BeMedia_SocialID, WebLink, ModifyTime FROM spot_user_sb_m tbSpot, media tbMedia
								  WHERE tbSpot.STORYBOARD_idSTORYBOARD = ".$rowBoard['idSTORYBOARD']."
								  AND tbSpot.USER_idUSER = ".$rowUserInfo['idUSER']."
								  AND tbSpot.MEDIA_idMEDIA = tbMedia.idMEDIA";

				// Get Media Item List
				$resultMediaList = mysql_query($strSqlCommand);
				while($rowMediaList = @mysql_fetch_array($resultMediaList))
				{
					$nID = $rowMediaList['idMEDIA'];
					// Get Comment Count
					/*
					$strSqlCommand = "SELECT COUNT(*) FROM COMMENTS WHERE MEDIA_idMEDIA = ".$rowMediaList['idMEDIA'];
					$resultComment = mysql_query($strSqlCommand);
					*/
					
					// Get Media Type
					$strSqlCommand = "SELECT Name FROM MEDIA_TYPE WHERE idMEDIA_TYPE = ".$rowMediaList['MEDIA_TYPE_idMEDIA_TYPE'];
					$resultMediaType = mysql_query($strSqlCommand);	
					$rowMediaType = @mysql_fetch_array($resultMediaType);
					
					if (strpos($rowMediaList['BeMedia_SocialID'], 'Facebook') !== false)
						$Source = "Facebook";
					else if (strpos($rowMediaList['BeMedia_SocialID'], 'Twitter') !== false)
						$Source = "Twitter";
					else if (strpos($rowMediaList['BeMedia_SocialID'], 'Tumblr') !== false)
						$Source = "Tumblr";
					else if (strpos($rowMediaList['BeMedia_SocialID'], 'Instagram') !== false)
						$Source = "Instagram";
					else if (strpos($rowMediaList['BeMedia_SocialID'], 'GoogleReader') !== false)
						$Source = "GoogleReader";
					else if (strpos($rowMediaList['BeMedia_SocialID'], 'DesignSponge') !== false)
						$Source = "DesignSponge";
					else if (strpos($rowMediaList['BeMedia_SocialID'], 'TheBump') !== false)
						$Source = "TheBump";
					else if (strpos($rowMediaList['BeMedia_SocialID'], 'DailyCandy') !== false)
						$Source = "DailyCandy";
					else if (strpos($rowMediaList['BeMedia_SocialID'], 'TheSartorialist') !== false)
						$Source = "TheSartorialist";
					else if (strpos($rowMediaList['BeMedia_SocialID'], 'Uncrate') !== false)
						$Source = "Uncrate";
					else if (strpos($rowMediaList['BeMedia_SocialID'], 'TheKitchn') !== false)
						$Source = "TheKitchn";
					else if (strpos($rowMediaList['BeMedia_SocialID'], 'LottieandDoof') !== false)
						$Source = "LottieandDoof";
					else if (strpos($rowMediaList['BeMedia_SocialID'], 'ApartmentTherapy') !== false)
						$Source = "ApartmentTherapy";
					else if (strpos($rowMediaList['BeMedia_SocialID'], 'CoolHunting') !== false)
						$Source = "CoolHunting";
					else if (strpos($rowMediaList['BeMedia_SocialID'], 'Themarthablog') !== false)
						$Source = "Themarthablog";
					else if (strpos($rowMediaList['BeMedia_SocialID'], 'HuffingtonPost') !== false)
						$Source = "HuffingtonPost";
					else if (strpos($rowMediaList['BeMedia_SocialID'], 'TinyWrld') !== false)
						$Source = "TinyWrld";
					else if (strpos($rowMediaList['BeMedia_SocialID'], 'StyleMePretty') !== false)
						$Source = "StyleMePretty";
					else
						$Source = "TPN";
					
					
					echo '<Media ID="'.$rowMediaList['idMEDIA'].'" BeMediaID="'.$rowMediaList['BeMedia_SocialID'].'" MediaType="'.$rowMediaType['Name'].'" WebLink="'.XMLCharEncode($rowMediaList['WebLink']).'" Source="'.$Source.'" Author="" lastUpdate="'.date("Y-m-d",strtotime($rowMediaList['ModifyTime'])).'" >'; 
					
					
					// Get GoogleReader Data
					if($rowMediaType['Name'] == "HTML"){
						$strSqlCommand = "SELECT * FROM TEXT tbText 
									  LEFT JOIN IMAGE tbImage	ON tbText.MEDIA_idMEDIA = tbImage.MEDIA_idMEDIA
									  WHERE tbImage.MEDIA_idMEDIA = ".$rowMediaList['idMEDIA'];
					 
						$resultText = mysql_query($strSqlCommand);	
						while($rowText = mysql_fetch_array($resultText))
						{
							if(isset($rowText['FileName'])){
								echo '<beHtml ThumbnailImage="'.$rowText['FileName'].'" ThumbnailWidth="'.$rowText['Width'].'" ThumbnailHeight="'.$rowText['Height'].'" Title="'.XMLCharEncode($rowText['Title']).'" Description="'.XMLCharEncode($rowText['Description']).'" ></beHtml>';
								
							}else{
								echo '<beHtml Title="'.XMLCharEncode($rowText['Title']).'" Description="'.XMLCharEncode($rowText['Description']).'" ></beHtml>';
							} 
						}  
					}else{
						// Get Text Data
						$strSqlCommand = "SELECT * FROM TEXT WHERE MEDIA_idMEDIA = ".$rowMediaList['idMEDIA'];
						$resultText = mysql_query($strSqlCommand);	
						while($rowText = mysql_fetch_array($resultText))
						{
							echo '<Text ID="'.$rowText['idText'].'" Title="'.XMLCharEncode($rowText['Title']).'" Description="'.XMLCharEncode($rowText['Description']).'" ></Text>';
						}
						// Get Image Data
						$strSqlCommand = "SELECT * FROM IMAGE WHERE MEDIA_idMEDIA = ".$rowMediaList['idMEDIA'];
						$resultImage = mysql_query($strSqlCommand);	
						while($rowImage = mysql_fetch_array($resultImage))
						{
							if( $rowImage['Type'] == "URL" )
								echo '<Image ID="'.$rowImage['idIMAGE'].'" Type="'.$rowImage['Type'].'" Width="'.$rowImage['Width'].'" Height="'.$rowImage['Height'].'" FileName="'.$rowImage['FileName'].'" />';
							else
								echo '<Image ID="'.$rowImage['idIMAGE'].'" Type="'.$rowImage['Type'].'" Width="'.$rowImage['Width'].'" Height="'.$rowImage['Height'].'" FileName="'.$ServerPath.$nID."/".$rowImage['FileName'].'" />';
						}
			
						// Get Video Data
						$strSqlCommand = "SELECT * FROM Video WHERE MEDIA_idMEDIA = ".$rowMediaList['idMEDIA'];
						$resultVideo = mysql_query($strSqlCommand);	
						while($rowVideo = mysql_fetch_array($resultVideo))
						{
							if( $rowVideo['Type'] == "URL" )
								echo '<Video ID="'.$rowVideo['idVideo'].'" Type="'.$rowVideo['Type'].'" FileName="'.$rowVideo['FileName'].'" />';
							else
								echo '<Video ID="'.$rowVideo['idVideo'].'" Type="'.$rowVideo['Type'].'" FileName="'.$ServerPath.$nID."/".$rowVideo['FileName'].'" />';
						}
							
					}
					
					//Get Comments
					while($rowComment = @mysql_fetch_array($resultComment)){ 
					
			        		echo '<Comment ID="'.$rowComment['idCOMMENTS'].'" Content="'.XMLCharEncode($rowComment['Comment']).'" User="'.$rowComment['Name'].'" lastUpdate="'.$rowComment['ModifyTime'].'"/>';
			        }
					
					//Get Notes
					$strSqlCommand = "SELECT idNOTES, NoteText, AxisX, AxisY
									FROM notes 
									LEFT JOIN USER                       ON NOTES.USER_idUSER = USER.idUSER 
									LEFT JOIN sharegroup                 ON USER.idUSER = sharegroup.USER_idUSER
									LEFT JOIN spot_group_users tbGU      ON sharegroup.idGROUP = tbGU.GROUP_idGROUP
							  		WHERE notes.MEDIA_idMEDIA = '".$nID."' AND tbGU.USER_idUSER=".$rowUserInfo['idUSER']."
									OR notes.MEDIA_idMEDIA = '".$nID."' AND sharegroup.USER_idUSER=".$rowUserInfo['idUSER']." 
									OR notes.MEDIA_idMEDIA = '".$nID."' AND USER.idUSER=".$rowUserInfo['idUSER']." GROUP BY idNOTES";
					$resultNote = mysql_query($strSqlCommand);
					 
					while($rowNote = mysql_fetch_array($resultNote))
					{ 
						 echo '<Note ID="'.$rowNote['idNOTES'].'" Text="'.XMLCharEncode($rowNote['NoteText']).'" AxisX="'.$rowNote['AxisX'].'" AxisY="'.$rowNote['AxisY'].'" ></Note>';
					}
					
					echo "</Media>";
   				 }
	
				//---------End of Media List-------------------------------------------------------------------------------//				
				echo '</Board>';
			}
			//---------End of Board List-------------------------------------------------------------------------------//

			echo "</MyBoard>";
		}
		// -----------------End of MyBoard---------------------//

		// Initialization
		echo "<Initialization>";
		
		/**
			// Channels
			$strSqlCommand = "SELECT idCHANNELS, Name 
									FROM CHANNELS";
			$resultCha = mysql_query($strSqlCommand);	
			while($rowCha = mysql_fetch_array($resultCha))
			{
				// Categories
				echo "<Categories>";
				
				if  (($rowCha['idCHANNELS']==0)||($rowCha['idCHANNELS']==1)) {
					
					$strSqlCommand = "SELECT idCATEGORY, Name 
									FROM CATEGORY";
					$resultCt = mysql_query($strSqlCommand);	
					while($rowCt = mysql_fetch_array($resultCt))
					{
						echo '<Category ID="'. $rowCt['idCATEGORY'] .'" Name="'.XMLCharEncode($rowCt['Name']).'" />';
					}
					
				}
				
				else {
					$strSqlCommand = "SELECT idCATEGORY, tbCat.Name AS CatName
									FROM CATEGORY tbCat
                                    LEFT JOIN SPOT_CY_CHl tbCCC		ON	tbCat.idCATEGORY = tbCCC.CATEGORY_idCATEGORY
                                    LEFT JOIN CHANNELS tbCha        ON 	tbCha.idCHANNELS = tbCCC.CHANNELS_idCHANNELS 
									WHERE tbCCC.CHANNELS_idCHANNELS = ".$rowCha['idCHANNELS'];
					$resultCt = mysql_query($strSqlCommand);	
					while($rowCt = mysql_fetch_array($resultCt))
					{
						echo '<Category ID="'. $rowCt['idCATEGORY'] .'" Name="'.XMLCharEncode($rowCt['CatName']).'" />';
					}
				}
				
				echo "</Categories>";
				// End of Categories
			}
			// End of Channels
		**/
		

			

			// Colors
			echo "<Colors>";
			
				$strSqlCommand = "SELECT Name, HexValue
									FROM COLOR,media 
									WHERE CHANNELS_idCHANNELS = ".$rowUserInfo['Default_Channel']." AND
									COLOR.idCOLOR = media.COLOR_idCOLOR GROUP BY Name, HexValue";
				$resultCt = mysql_query($strSqlCommand);	
				while($rowCt = mysql_fetch_array($resultCt))
				{
					echo '<Color Name="'. $rowCt['Name'] .'" HexValue="'.$rowCt['HexValue'].'" />';
				}
			
			echo "</Colors>";
			// End of Colors

			// Tags
			echo "<Tags>";
				$strSqlCommand = "SELECT Name, Priority
									FROM TAGS, spot_tag_media tbTM
									WHERE CHANNELS_idCHANNELS = ".$rowUserInfo['Default_Channel']." AND
									TAGS.idTAGS = tbTM.TAGS_idTAGS GROUP BY Name, Priority";
				$resultCt = mysql_query($strSqlCommand);	
				while($rowCt = mysql_fetch_array($resultCt))
				{
					echo '<Tags Name="'. $rowCt['Name'] .'" Size="'.$rowCt['Priority'].'" />';
				}
			
			echo "</Tags>";
			// End of Categories
	
		echo "</Initialization>";
		// End of Initialization
		
		//Get Recommended Feeds.
		$strSqlCommand = "SELECT Name, Content, URL
									FROM recommended_feed";
		$resultReFeed = mysql_query($strSqlCommand);	
		while($rowReFeed = mysql_fetch_array($resultReFeed))
		{
			echo '<RecommendedFeed Title="'. XMLCharEncode($rowReFeed['Name']) .'" Content="'. XMLCharEncode($rowReFeed['Content']) .'" Link="'.XMLCharEncode($rowReFeed['URL']).'" />';
		}
		// End of Recommended Feeds.
		
		//Get Account Feed.
		$strSqlCommand = "SELECT Title, Description, URL, Switch
									FROM spot_user_googlefeed 
									WHERE USER_idUSER= ".$rowUserInfo['idUSER']."";
									
		$resultGoogleFeed = mysql_query($strSqlCommand);
		
		if ((isset($rowUserInfo['FaceBookID']))||(isset($rowUserInfo['TwitterKey']))||(isset($rowUserInfo['TumblrName']))||
		(isset($rowUserInfo['InstagramToken']))||(@mysql_num_rows($resultGoogleFeed)>0))
		{
			// Begin of Feed
			echo "<Feed>";
			
			if (isset($rowUserInfo['FaceBookID']))
				echo '<Facebook ID="'.$rowUserInfo['FaceBookID'].'" Token="'.$rowUserInfo['FaceBookToken'].'" Switch="'.$rowUserInfo['FaceBookSwitch'].'" />';
				
			if (isset($rowUserInfo['TwitterKey']))
				echo '<Twitter Key="'.$rowUserInfo['TwitterKey'].'" Secret="'.$rowUserInfo['TwitterSecret'].'" Switch="'.$rowUserInfo['TwitterSwitch'].'" />';
				
			if (isset($rowUserInfo['TumblrName']))
				echo '<Tumblr Name="'.$rowUserInfo['TumblrName'].'" Switch="'.$rowUserInfo['TumblrSwitch'].'" />';
				
			if (isset($rowUserInfo['InstagramToken']))
				echo '<Instagram Token="'.$rowUserInfo['InstagramToken'].'" Switch="'.$rowUserInfo['InstagramSwitch'].'" />';
		
			if (@mysql_num_rows($resultGoogleFeed) > 0 )
				while($rowGoogleFeed = mysql_fetch_array($resultGoogleFeed))
					echo '<GoogleFeed Title="'. XMLCharEncode($rowGoogleFeed['Title']) .'" Content="'.XMLCharEncode($rowGoogleFeed['Description']).'" Link="'.XMLCharEncode($rowGoogleFeed['URL']).'" Switch="'.$rowGoogleFeed['Switch'].'" />';
		
			// End of Feed
			echo "</Feed>";
		}
		
		echo '</AccountInfo>';		

	}
	else
	{
		echo '<AccountInfo UserName="" Level="" Name="" Organization="" Channel="" Enable="">';	
		
		// Initialization
		echo "<Initialization>";

			// Categories
			/***echo "<Categories>";

				$strSqlCommand = "SELECT Name 
									FROM CATEGORY 
									WHERE CHANNELS_idCHANNELS = 0";//.$rowUserInfo['Default_Channel'];
				$resultCt = mysql_query($strSqlCommand);	
				while($rowCt = mysql_fetch_array($resultCt))
				{
					echo '<Category Name="'. $rowCt['Name'] .'" />';
				}
			
			echo "</Categories>";***/
			// End of Categories

			// Colors
			echo "<Colors>";
				$strSqlCommand = "SELECT Name, HexValue 
				                   FROM COLOR,media 
								   WHERE COLOR.CHANNELS_idCHANNELS = 0 AND 
								   COLOR.idCOLOR = media.COLOR_idCOLOR GROUP BY Name, HexValue";//.$rowUserInfo['Default_Channel'];
				$resultCt = mysql_query($strSqlCommand);	
				while($rowCt = mysql_fetch_array($resultCt))
				{
					echo '<Color Name="'. $rowCt['Name'] .'" HexValue="'.$rowCt['HexValue'].'" />';
				}
			
			echo "</Colors>";
			// End of Colors

			// Tags
			echo "<Tags>";
				$strSqlCommand = "SELECT Name, Priority
									FROM TAGS, spot_tag_media tbTM
									WHERE CHANNELS_idCHANNELS = 0 AND
									TAGS.idTAGS = tbTM.TAGS_idTAGS GROUP BY Name, Priority";
			$resultCt = mysql_query($strSqlCommand);	
			while($rowCt = mysql_fetch_array($resultCt))
			{
				echo '<Tags Name="'. $rowCt['Name'] .'" Size="'.$rowCt['Priority'].'" />';
			}
			
			echo "</Tags>";
			// End of Categories
			
		echo "</Initialization>";
		// End of Initialization
			
		echo '</AccountInfo>';
	}
	
	function XMLCharEncode( $Subject )
	{
		$Serach  = array( "<", ">", "&", "'","\"" );
		$Replace = array( "&lt;","&gt;","&amp;","&apos;","&quot;");
		return str_replace($Serach, $Replace, $Subject);
	}
?>